package com.ly.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ly.demo.entity.Student;
import com.ly.demo.service.StudentService;
import com.ly.demo.service.impl.StudentServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Api(tags = "学生相关接口")
@Controller
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;
//    @GetMapping("/list")
//    @ResponseBody
//    public List<Student> list(){
//        return studentService.list();
//    }
    @ApiOperation("根据id查询学生信息")
    @GetMapping(value = "/hello/{id}")
    public String getUser(@PathVariable("id") @ApiParam("主键")Long sid,
                          Model model) {
        Student user = studentService.getById(sid);
        List<Student> users = studentService.list();
        model.addAttribute("date", new Date());
        model.addAttribute("user", user);
        model.addAttribute("users", users);
        return "list";
    }
}
